package com.slz3.business.module.systemManagement.sysRoleMenu.steward;

import com.slz3.business.frame.enums.AuditFlag;
import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.response.RR;
import com.slz3.business.frame.util.VE;
import com.slz3.business.module.systemManagement.sysRoleMenu.domain.SysRoleMenu;
import com.slz3.business.module.systemManagement.sysRoleMenu.domain.SysRoleMenuCondition;
import org.springframework.web.reactive.function.server.ServerRequest;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public class SysRoleMenuResSafeValid {

    static boolean add(ServerRequest req, SysRoleMenu sysRoleMenu) {
        // T-O-D-O 唯一约束
        return RR.hasResErr(req);
    }

    /**
     * known: params uuids is not null
     */
    static final boolean delete(ServerRequest req, SysRoleMenuCondition sysRoleMenuCondition) {
        List<SysRoleMenu> sysRoleMenuList = Services.sysRoleMenu.findAllByUuids(sysRoleMenuCondition.getUuidList());
        req.attributes().put(RR.RELAY_SAFE_VALID, sysRoleMenuList);
        return RR.hasResErr(req);
    }

    static boolean modify(ServerRequest req, SysRoleMenu sysRoleMenu) {
        Optional<SysRoleMenu> sysRoleMenuDB = Services.sysRoleMenu.single(sysRoleMenu.getUuid());
        if (sysRoleMenuDB.isPresent()) {
            req.attributes().put(RR.RELAY_SAFE_VALID, sysRoleMenuDB.get());
        } else {
            RR.resDetail(req).put(RR.SAFE_VALID, "cannot find entity by request uuid");
        }
        return RR.hasResErr(req);
    }

    static boolean info(ServerRequest req) {
        Optional<SysRoleMenu> sysRoleMenuDB = Services.sysRoleMenu.single(UUID.fromString(req.queryParam("uuid").get()));
        if (!sysRoleMenuDB.isPresent()) {
            RR.resDetail(req).put(RR.SAFE_VALID, "cannot find entity by request uuid");
        } else {
            req.attributes().put(RR.RELAY_SAFE_VALID, sysRoleMenuDB.get());
        }
        return RR.hasResErr(req);
    }

}
